package com.yzs.exam.config.spring.security;

import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;

import javax.servlet.http.HttpServletRequest;

/**
 * 自定义记住我功能--基于简单加密 token 的实现
 * 服务端发送cookies给客户端保存，下次浏览器访问系统时候，会检测cookies，触发自动登录
 * 两种实现：1.简单的加密 2.持久化token到数据库
 * @author yzs
 * @create 2021-03-21 2:49
 */
public class RestTokenBasedRememberMeServices extends TokenBasedRememberMeServices {
    public RestTokenBasedRememberMeServices(String key, UserDetailsService userDetailsService) {
        super(key, userDetailsService);
    }

    @Override
    protected boolean rememberMeRequested(HttpServletRequest request, String parameter) {
        return (boolean) request.getAttribute(DEFAULT_PARAMETER);//判断是否有记住我这个属性
    }
}
